package com.example.zhinongbao.view;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.example.zhinongbao.R;


public class OrdersActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView Back ;
    private TextView BuyEnter , SaleOut ,AllOrders , WaitShipments , WaitReceiving , Done , AfterSales ;
    private RecyclerView OrderList ;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.orders);
        Back = findViewById(R.id.orders_back) ;
        BuyEnter = findViewById(R.id.orders_buy_enter) ;
        SaleOut = findViewById(R.id.orders_sale_out) ;
        AllOrders = findViewById(R.id.orders_all_order) ;
        WaitShipments = findViewById(R.id.orders_wait_shipments) ;
        WaitReceiving = findViewById(R.id.orders_wait_receiving) ;
        Done = findViewById(R.id.orders_done) ;
        AfterSales = findViewById(R.id.orders_after_sales) ;
        OrderList = findViewById(R.id.orders_show_list) ;
        titleTestSetSelected();

        Back.setOnClickListener(this);
        BuyEnter.setOnClickListener(this);
        SaleOut.setOnClickListener(this);
        AllOrders.setOnClickListener(this);
        WaitShipments.setOnClickListener(this);
        WaitReceiving.setOnClickListener(this);
        Done.setOnClickListener(this);
        AfterSales.setOnClickListener(this);
        Bundle getIntent = getIntent().getExtras();
        if (getIntent != null){
            int caseOrder = getIntent.getInt("case");
            if (caseOrder <= 5){
                BuyEnter.setSelected(true);
                if (caseOrder == 1){
                    AllOrders.setSelected(true);
                } else if (caseOrder == 2) {
                    WaitShipments.setSelected(true);
                } else if (caseOrder == 3) {
                    WaitReceiving.setSelected(true);
                } else if (caseOrder == 4) {
                    Done.setSelected(true);
                } else if (caseOrder == 5) {
                    AfterSales.setSelected(true);
                }
            }else {
                SaleOut.setSelected(true);
                AllOrders.setSelected(true);
            }
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.orders_back){
            onBackPressed();
        } else if (v.getId() == R.id.orders_buy_enter) {
            BuyEnter.setSelected(true);
            SaleOut.setSelected(false);
        } else if (v.getId() == R.id.orders_sale_out) {
            BuyEnter.setSelected(false);
            SaleOut.setSelected(true);
        } else if (v.getId() == R.id.orders_all_order) {
            AllOrders.setSelected(true);
            WaitShipments.setSelected(false);
            WaitReceiving.setSelected(false);
            Done.setSelected(false);
            AfterSales.setSelected(false);
        }else if (v.getId() == R.id.orders_wait_shipments) {
            AllOrders.setSelected(false);
            WaitShipments.setSelected(true);
            WaitReceiving.setSelected(false);
            Done.setSelected(false);
            AfterSales.setSelected(false);
        }else if (v.getId() == R.id.orders_wait_receiving) {
            AllOrders.setSelected(false);
            WaitShipments.setSelected(false);
            WaitReceiving.setSelected(true);
            Done.setSelected(false);
            AfterSales.setSelected(false);
        }else if (v.getId() == R.id.orders_done) {
            AllOrders.setSelected(false);
            WaitShipments.setSelected(false);
            WaitReceiving.setSelected(false);
            Done.setSelected(true);
            AfterSales.setSelected(false);
        }else if (v.getId() == R.id.orders_after_sales) {
            AllOrders.setSelected(false);
            WaitShipments.setSelected(false);
            WaitReceiving.setSelected(false);
            Done.setSelected(false);
            AfterSales.setSelected(true);
        }
    }

    public void titleTestSetSelected(){
        if (BuyEnter.isSelected()){
            SaleOut.setSelected(false);
        }else if(SaleOut.isSelected()){
            BuyEnter.setSelected(false);
        }
        if (AllOrders.isSelected()){
            WaitShipments.setSelected(false);
            WaitReceiving.setSelected(false);
            Done.setSelected(false);
            AfterSales.setSelected(false);
        } else if (WaitShipments.isSelected()) {
            AllOrders.setSelected(false);
            WaitReceiving.setSelected(false);
            Done.setSelected(false);
            AfterSales.setSelected(false);
        } else if (WaitReceiving.isSelected()) {
            AllOrders.setSelected(false);
            WaitShipments.setSelected(false);
            Done.setSelected(false);
            AfterSales.setSelected(false);
        } else if (Done.isSelected()) {
            AllOrders.setSelected(false);
            WaitShipments.setSelected(false);
            WaitReceiving.setSelected(false);
            AfterSales.setSelected(false);
        } else if (SaleOut.isSelected()) {
            AllOrders.setSelected(false);
            WaitShipments.setSelected(false);
            WaitReceiving.setSelected(false);
            Done.setSelected(false);
        }
    }
}
